"use strict"

import {Body,Controller, Inject, Post, Provide} from "@midwayjs/decorator";
import UserRoleService from "../service/userRoleService";
import RoleUserService from "../../role/service/roleUserService";

@Provide()
@Controller('/userRole')
export class UserRoleController{
  @Inject()
  userRoleService: UserRoleService;
  @Inject()
  roleUserService: RoleUserService;

  @Post('/save')
  async userRoleSave(@Body('userRoleList') data:object){
    const rs=await this.roleUserService.save(data).catch(err=>{
      return{
        success:false,
        msg:'保存失败'
      }
    })
    return rs;
  }
  @Post('/getUserRoleList')
  async getUserRoleList(@Body('userId') userId:string){
    //获取用户已经分配的角色
    const rs=await this.userRoleService.getUserRoleList(userId).catch(err=>{
      return {
        success: false,
        msg:'获取数据失败'
      }
    })
    return rs;
  }
  @Post('/getNotUserRoleList')
  async getNotUserRoleList(@Body('userId') userId:string){
    //获取用户未已经分配的角色
    const rs=await this.userRoleService.getNotUserRoleList(userId).catch(err=>{
      return {
        success: false,
        msg:'获取数据失败'
      }
    })
    return rs;
  }

}
